#include "Background.h"


Background::Background(){
	backgroundOn = true;
}

void Background::draw(int trackLength, int eyeZ, int posZ, Image* backgroundIMG, GLuint backgroundID){

	glPushMatrix();

		glColor3f(1,1,1);

		glPushMatrix();
			//glRotated(90,1,0,0);
			glTranslated(0, -125, eyeZ + posZ - 620);
			glScalef(trackLength / 125,trackLength / 125,0);
			
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, backgroundID);
			//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			// //environment mapping
			//glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
			//glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
			//glEnable(GL_TEXTURE_GEN_S);
			//glEnable(GL_TEXTURE_GEN_T);
			//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, backgroundIMG->pixels);

			//glutSolidCube(1);

			glBegin(GL_QUADS);

			glNormal3f(0,1,0);
			glTexCoord3f(0,0,0);
			glVertex3f(-100,0,0);

			glTexCoord3f(1,0,0);
			glVertex3f(100,0,0);

			glTexCoord3f(1,1,0);
			glVertex3f(100,100,0);

			glTexCoord3f(0,1,0);
			glVertex3f(-100,100,0);


			glEnd();

			glDisable(GL_TEXTURE_2D);
			
		glPopMatrix();

	glPopMatrix();
}

void Background::draw(int width, int height, Image* backgroundIMG, GLuint backgroundID){

	glPushMatrix();

		glColor3f(1,1,1);

		glPushMatrix();

			//glScalef(0.04f, 0.04f,0);
			glTranslated(-400, -300, -700);
			
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, backgroundID);
			//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

			//glutSolidCube(1);

			glBegin(GL_QUADS);

			glNormal3f(0,1,0);
						
			glTexCoord3f(0,0,0);
			glVertex3f(0,0,0);

			glTexCoord3f(1,0,0);
			glVertex3f(width,0,0);

			glTexCoord3f(1,1,0);
			glVertex3f(width,height,0);

			glTexCoord3f(0,1,0);
			glVertex3f(0,height,0);

			
			glEnd();

			glDisable(GL_TEXTURE_2D);
			
		glPopMatrix();

	glPopMatrix();
}